﻿using System;
using UnityEngine;

namespace RootMotion.FinalIK
{
	// Token: 0x02000076 RID: 118
	public class Amplifier : OffsetModifier
	{
		// Token: 0x060004C0 RID: 1216 RVA: 0x00031660 File Offset: 0x0002F860
		public override void OnModifyOffset()
		{
			if (!this.ik.fixTransforms)
			{
				if (!Warning.logged)
				{
					Warning.Log("Amplifier needs the Fix Transforms option of the FBBIK to be set to true. Otherwise it might amplify to infinity, should the animator of the character stop because of culling.", base.transform, false);
				}
				return;
			}
			foreach (Amplifier.Body body in this.bodies)
			{
				body.Update(this.ik.solver, this.weight, base.deltaTime);
			}
		}

		// Token: 0x0400033C RID: 828
		[Tooltip("The amplified bodies.")]
		public Amplifier.Body[] bodies;

		// Token: 0x02000077 RID: 119
		[Serializable]
		public class Body
		{
			// Token: 0x060004C2 RID: 1218 RVA: 0x000316D8 File Offset: 0x0002F8D8
			public void Update(IKSolverFullBodyBiped solver, float w, float deltaTime)
			{
				if (this.transform == null || this.relativeTo == null)
				{
					return;
				}
				Vector3 a = this.relativeTo.InverseTransformDirection(this.transform.position - this.relativeTo.position);
				if (this.firstUpdate)
				{
					this.lastRelativePos = a;
					this.firstUpdate = false;
				}
				Vector3 vector = (a - this.lastRelativePos) / deltaTime;
				this.smoothDelta = ((this.speed > 0f) ? Vector3.Lerp(this.smoothDelta, vector, deltaTime * this.speed) : vector);
				Vector3 v = this.relativeTo.TransformDirection(this.smoothDelta);
				Vector3 a2 = V3Tools.ExtractVertical(v, solver.GetRoot().up, this.verticalWeight) + V3Tools.ExtractHorizontal(v, solver.GetRoot().up, this.horizontalWeight);
				for (int i = 0; i < this.effectorLinks.Length; i++)
				{
					solver.GetEffector(this.effectorLinks[i].effector).positionOffset += a2 * w * this.effectorLinks[i].weight;
				}
				this.lastRelativePos = a;
			}

			// Token: 0x060004C3 RID: 1219 RVA: 0x00031834 File Offset: 0x0002FA34
			public static Vector3 Multiply(Vector3 v1, Vector3 v2)
			{
				v1.x *= v2.x;
				v1.y *= v2.y;
				v1.z *= v2.z;
				return v1;
			}

			// Token: 0x0400033D RID: 829
			[Tooltip("The Transform that's motion we are reading.")]
			public Transform transform;

			// Token: 0x0400033E RID: 830
			[Tooltip("Amplify the 'transform's' position relative to this Transform.")]
			public Transform relativeTo;

			// Token: 0x0400033F RID: 831
			[Tooltip("Linking the body to effectors. One Body can be used to offset more than one effector.")]
			public Amplifier.Body.EffectorLink[] effectorLinks;

			// Token: 0x04000340 RID: 832
			[Tooltip("Amplification magnitude along the up axis of the character.")]
			public float verticalWeight = 1f;

			// Token: 0x04000341 RID: 833
			[Tooltip("Amplification magnitude along the horizontal axes of the character.")]
			public float horizontalWeight = 1f;

			// Token: 0x04000342 RID: 834
			[Tooltip("Speed of the amplifier. 0 means instant.")]
			public float speed = 3f;

			// Token: 0x04000343 RID: 835
			public Vector3 lastRelativePos;

			// Token: 0x04000344 RID: 836
			public Vector3 smoothDelta;

			// Token: 0x04000345 RID: 837
			public bool firstUpdate;

			// Token: 0x02000078 RID: 120
			[Serializable]
			public class EffectorLink
			{
				// Token: 0x04000346 RID: 838
				[Tooltip("Type of the FBBIK effector to use")]
				public FullBodyBipedEffector effector;

				// Token: 0x04000347 RID: 839
				[Tooltip("Weight of using this effector")]
				public float weight;
			}
		}
	}
}
